package com.xquant.marketdata.curvestrip.controller;

import com.github.pagehelper.PageInfo;
import com.xquant.marketdata.curvestrip.entity.CheckParam;
import com.xquant.marketdata.curvestrip.service.TdefCurveService;
import com.xquant.marketdata.utils.CommResponse;
import com.xquant.marketdata.utils.ResponseVo;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: xpp -_- -_-
 * @Date: 2021/3/16 16:23
 */
@RestController
@RequestMapping("/defCurve")
public class TdefCurveController {
    @Autowired
    private TdefCurveService tdefCurveService;

    @RequestMapping("/listDefByPage.action")
    public PageInfo TdefCurveDefList(@RequestParam Map<String, Object> params) {
        return tdefCurveService.TdefCurveListByPage(params);
    }

    @RequestMapping("/saveTdefCurve.action")
    public Object saveTdefCurve(@RequestParam Map<String, Object> params) {
        List list = tdefCurveService.findDefcurveByCode(MapUtils.getString(params, "defcCode", ""));
        if (list.size() > 0) {
            return CommResponse.failure("违约曲线已存在");
        }
        tdefCurveService.saveTdefCurve(params);
         return CommResponse.success("操作成功");
    }

    @RequestMapping("/updateTdefCurveByDeCode.action")
    public Object updateTdefCurveByDeCode(@RequestParam Map<String, Object> params) {
        tdefCurveService.updateTdefCurveByDeCode(params);
         return CommResponse.success("操作成功");
    }

    @RequestMapping("/deleteByPrimarydefcCode.action")
    public Object deleteByPrimarydefcCode(@RequestParam Map<String, Object> params) {
        tdefCurveService.deleteByPrimarydefcCode(params);

        return CommResponse.success("操作成功");
    }

    @RequestMapping("/listTdefcurveRatesByPage.action")
    public PageInfo listTdefcurveRatesByPage(@RequestParam Map<String, Object> params) {
        return tdefCurveService.TdefcurveRatesListByPage(params);
    }

    @RequestMapping("/saveTdefcurveRates.action")
    public Object saveTdefcurveRates(@RequestParam Map<String, Object> params) {
        tdefCurveService.saveTdefcurveRates(params);
        return CommResponse.success("操作成功");
    }

    @RequestMapping("/updateTdefcurveRates.action")
    public Object updateTdefcurveRates(@RequestParam Map<String, Object> params) {
        tdefCurveService.updateTdefcurveRates(params);
        return CommResponse.success("操作成功");
    }

    @RequestMapping("/deleteTdefcurveRates.action")
    public Object deleteTdefcurveRates(@RequestParam Map<String, Object> params) {
        tdefCurveService.deleteTdefcurveRates(params);
        return CommResponse.success("操作成功");
    }

    @RequestMapping("/listTdefcurveRefSet.action")
    public PageInfo TdefcurveRefSetList(@RequestParam Map<String, Object> params) {
        return tdefCurveService.TdefcurveRefSetByPage(params);
    }

    @RequestMapping("/saveTdefcurveRefSet.action")
    public Object saveTdefcurveRefSet(@RequestParam Map<String, Object> params) {
        tdefCurveService.saveTdefcurveRefSet(params);
        return CommResponse.success("操作成功");
    }

    @RequestMapping("/updateTdefcurveRefSet.action")
    public Object updateTdefcurveRefSet(@RequestParam Map<String, Object> params) {
        tdefCurveService.updateTdefcurveRefSet(params);
        return CommResponse.success("操作成功");
    }

    @RequestMapping("/deleteTdefcurveRefSet.action")
    public Object deleteTdefcurveRefSet(@RequestParam Map<String, Object> params) {
        tdefCurveService.deleteTdefcurveRefSet(params);
        return CommResponse.success("操作成功");
    }

    @RequestMapping("/checkDefCurveRates.action")
    public Object checkDefCurveRates(@RequestBody CheckParam params) {

        int count = tdefCurveService.checkDefCurveRates(params);

        return ResponseVo.success(count == 0 ? false : true);
    }

}
